package cuiyt.algorithm.dfs;


import java.util.Arrays;
import java.util.List;

/**
 * @author cyt
 * @create 2020-09-02 下午 4:34
 */
public class B {
    public static void main(String[] args) {
        B b = new B();
        int[] person;
        // person = new int[]{4, 1, 3, 3, 3};
        // person = new int[]{1,2,3,4,5,6,1};
        person = new int[]{1, 2, 3, 2, 2};
        System.out.println(b.house(person));
    }

    public int house(int[] person) {
        int[] ints = new int[person.length];
        List<int[]> asList = Arrays.asList(person);
        int index = 0;
        int min = person[0];
        for (int i = 0; i < person.length; i++) {
            if (person[i] < min) {
                min = person[i];
                index = i;
            }
        }
        ints[index] = 1;


        int i = index;
        int j = index;

        while (i < person.length - 1) {
            if (person[i + 1] > person[i]) {
                ints[i + 1] = 2;
            } else {
                ints[i + 1] = 1;
            }

            if (j > 0) {
                if (person[j - 1] > person[j]) {
                    ints[j - 1] = 2;
                } else {
                    ints[j - 1] = 1;
                }
                j--;
            }
            i++;
        }


        int sum = 0;
        for (int anInt : ints) {
            System.out.println(anInt);
        }
        for (int anInt : ints) {
            sum += anInt;
        }
        return sum;
    }
}
